package com.haozhiyan.zhijian.myDao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.haozhiyan.zhijian.bean.workfg.WorkPlotBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "WORK_PLOT_BEAN".
*/
public class WorkPlotBeanDao extends AbstractDao<WorkPlotBean, String> {

    public static final String TABLENAME = "WORK_PLOT_BEAN";

    /**
     * Properties of entity WorkPlotBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
    */
    public static class Properties {
        public final static Property PkId = new Property(0, String.class, "pkId", true, "PK_ID");
        public final static Property IteamName = new Property(1, String.class, "iteamName", false, "ITEAM_NAME");
        public final static Property ItemId = new Property(2, String.class, "itemId", false, "ITEM_ID");
    };

    private Query<WorkPlotBean> workProjectBean_ChildsQuery;

    public WorkPlotBeanDao(DaoConfig config) {
        super(config);
    }
    
    public WorkPlotBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"WORK_PLOT_BEAN\" (" + //
                "\"PK_ID\" TEXT PRIMARY KEY NOT NULL ," + // 0: pkId
                "\"ITEAM_NAME\" TEXT," + // 1: iteamName
                "\"ITEM_ID\" TEXT);"); // 2: itemId
        // Add Indexes
        db.execSQL("CREATE UNIQUE INDEX " + constraint + "IDX_WORK_PLOT_BEAN_PK_ID ON WORK_PLOT_BEAN" +
                " (\"PK_ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"WORK_PLOT_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, WorkPlotBean entity) {
        stmt.clearBindings();
 
        String pkId = entity.getPkId();
        if (pkId != null) {
            stmt.bindString(1, pkId);
        }
 
        String iteamName = entity.getIteamName();
        if (iteamName != null) {
            stmt.bindString(2, iteamName);
        }
 
        String itemId = entity.getItemId();
        if (itemId != null) {
            stmt.bindString(3, itemId);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, WorkPlotBean entity) {
        stmt.clearBindings();
 
        String pkId = entity.getPkId();
        if (pkId != null) {
            stmt.bindString(1, pkId);
        }
 
        String iteamName = entity.getIteamName();
        if (iteamName != null) {
            stmt.bindString(2, iteamName);
        }
 
        String itemId = entity.getItemId();
        if (itemId != null) {
            stmt.bindString(3, itemId);
        }
    }

    @Override
    public String readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
    }    

    @Override
    public WorkPlotBean readEntity(Cursor cursor, int offset) {
        WorkPlotBean entity = new WorkPlotBean( //
            cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0), // pkId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // iteamName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2) // itemId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, WorkPlotBean entity, int offset) {
        entity.setPkId(cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0));
        entity.setIteamName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setItemId(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
     }
    
    @Override
    protected final String updateKeyAfterInsert(WorkPlotBean entity, long rowId) {
        return entity.getPkId();
    }
    
    @Override
    public String getKey(WorkPlotBean entity) {
        if(entity != null) {
            return entity.getPkId();
        } else {
            return null;
        }
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "childs" to-many relationship of WorkProjectBean. */
    public List<WorkPlotBean> _queryWorkProjectBean_Childs(String itemId) {
        synchronized (this) {
            if (workProjectBean_ChildsQuery == null) {
                QueryBuilder<WorkPlotBean> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ItemId.eq(null));
                workProjectBean_ChildsQuery = queryBuilder.build();
            }
        }
        Query<WorkPlotBean> query = workProjectBean_ChildsQuery.forCurrentThread();
        query.setParameter(0, itemId);
        return query.list();
    }

}
